//
//  YCServiceFactory.swift
//  YCNetworking
//
//  Created by YC on 2017/3/7.
//  Copyright © 2017年 YC. All rights reserved. mail:yangchong364@qq.com
//

import UIKit

class YCServiceFactory {
    static let shared = YCServiceFactory()
    
    private var serviceStorage = [String : YCService]()
    
    private init() {

    }
    
    func service(with identifier: String) -> YCService {
        if self.serviceStorage[identifier] == nil {
            self.serviceStorage[identifier] = self.newService(with: identifier)
        }
        
        return self.serviceStorage[identifier]!
    }
    
    func newService(with identifier: String) -> YCService! {
        var service: YCService?
        
        if identifier == Services.login {
            service = LoginService()
        }else if identifier == Services.task {
            service = TaskService()
        }else if identifier == Services.doc {
            service = DocService()
        }else if identifier == Services.h5 {
            service = H5Service()
        }else if identifier == Services.signalr {
            service = SignalrService()
        }else if identifier == Services.meeting {
            
        }else if identifier == Services.taskExtension {
            service = TaskExtensionService()
        }else if identifier == Services.message {
            service = MessageService()
        }
        
        if service != nil {
            self.serviceStorage[identifier] = service
            
            return service
        }
        
        return nil
    }
    
}
